package com.ycy.chuwenuniapp.controller;


import com.ycy.chuwenuniapp.common.ResData;
import com.ycy.chuwenuniapp.entity.MyFile;
import com.ycy.chuwenuniapp.service.MyFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "文件管理")
@RestController
@RequestMapping("/file")
public class MyFileController {
    @Resource
    MyFileService myFileService;

    @PostMapping("/upload")
    @ApiOperation("上传")
    public ResData<MyFile> upload(@RequestPart MultipartFile file) {
        return myFileService.upload(file);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public ResData<Boolean> delete(String url) {
        return myFileService.delete(url);
    }

    @GetMapping("/download")
    @ApiOperation("下载")
    public void download(@RequestParam String uniqueName, HttpServletResponse response) {
        myFileService.download(uniqueName,response);
    }

    @PostMapping("/updateAvatar")
    @ApiOperation("更换头像")
    public ResData<MyFile> updateAvatar(@RequestPart MultipartFile file, String userId) {
        return myFileService.updateAvatar(file,userId);
    }

//    @PostMapping("/updateGoodsImg")
//    @ApiOperation("更换商品图片")
//    public ResData<MyFile> updateGoodsImg(@RequestPart MultipartFile file, String goodsId) {
//        return myFileService.updateGoodsImg(file,goodsId);
//    }
}
